﻿#ifndef MODBUSTCPSLAVE_H
#define MODBUSTCPSLAVE_H

#include <QObject>
#include <QModbusTcpServer>
#include "basecommunication.h"

class ModbusTcpSlave : public BaseCommunication
{
    Q_OBJECT
public:
    Q_INVOKABLE explicit ModbusTcpSlave(QObject *parent = nullptr);

signals:

public slots:

    // BaseCommunication interface
public:
    virtual bool connectToHost() override;
    virtual bool isConnected() override;
    virtual bool disConnect() override;

    void WriteRegister(int address, int val);

signals:
    void DataWritten(QModbusDataUnit::RegisterType,int address, int val);

//    bool Write

private slots:
    void onStateChanged(QModbusDevice::State state);
    void onDataWritten(QModbusDataUnit::RegisterType table, int address, int size);

private:
    QModbusTcpServer *_modbusServer=nullptr;
};


#endif // TCPMODBUSSERVER_H
